/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmCalendar.java
 *
 * Created on 22/12/2010, 11:23:34
 */

package scc.Telas;

import java.text.SimpleDateFormat;
import javax.swing.JFormattedTextField;

/**
 *
 * @author davidson
 */
public class frmCalendar extends javax.swing.JDialog {

    private JFormattedTextField ftfData;
    /** Creates new form frmCalendar */
    public frmCalendar(java.awt.Frame parent, boolean modal, JFormattedTextField ftfData) {
        super(parent, modal);
        initComponents();
        this.ftfData = ftfData;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dpCalendar = new net.sf.nachocalendar.components.DatePanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMaximumSize(new java.awt.Dimension(224, 140));
        setMinimumSize(new java.awt.Dimension(224, 140));
        setPreferredSize(new java.awt.Dimension(224, 140));
        setResizable(false);
        setUndecorated(true);

        dpCalendar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        dpCalendar.setMaximumSize(new java.awt.Dimension(224, 140));
        dpCalendar.setMinimumSize(new java.awt.Dimension(224, 140));
        dpCalendar.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                dpCalendarStateChanged(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(dpCalendar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(26, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(dpCalendar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(40, Short.MAX_VALUE))
        );

        setBounds(12, 110, 250, 180);
    }// </editor-fold>//GEN-END:initComponents

    private void dpCalendarStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_dpCalendarStateChanged
        
        if (ftfData.getText().length() == 10){
            ftfData.setText(new SimpleDateFormat("dd/MM/yyyy").format(dpCalendar.getValue()));
            setVisible(false);
        } else {
            String hora = ftfData.getText().substring(13, 18);
            ftfData.setText(new SimpleDateFormat("dd/MM/yyyy").format(dpCalendar.getValue())+hora);
            setVisible(false);
        }
    }//GEN-LAST:event_dpCalendarStateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private net.sf.nachocalendar.components.DatePanel dpCalendar;
    // End of variables declaration//GEN-END:variables

}
